import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/app_colors.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

Future<bool?> showConfirm({
  String title = "",
  String content = "",
  Color? contentColor,
  Widget? child,
  bool? showCancelBtn = false,
  double? height,
  double? width,
  String cancelText = "取消",
  String sureText = "确认",
}) async {
  var res = await Get.dialog(
    Center(
      child: Material(
        color: Colors.transparent,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 40),
          child: Container(
            padding: EdgeInsets.all(16),
            width: double.infinity,
            decoration: BoxDecoration(
              color: Color(0xff030F18),
              borderRadius: BorderRadius.circular(12),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                if (title.isNotEmpty)
                  Text(
                    title,
                    style: TextStyle(color: AppColors.primaryTextColor, fontSize: 16, fontWeight: FontWeight.w500),
                  ),
                if (child != null || content.isNotEmpty)
                  child ??
                      Container(
                        margin: const EdgeInsets.only(top: 8),
                        child: Text(
                          content,
                          style: TextStyle(color: Colors.white, fontSize: 14, height: 2),
                        ),
                      ),
                Container(
                  height: 40,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      if (showCancelBtn == true) ...[
                        Expanded(
                          child: InkWell(
                            onTap: () {
                              Get.back(result: false);
                            },
                            child: Container(
                              alignment: Alignment.center,
                              child: Text(
                                cancelText,
                                style: TextStyle(fontSize: 16, color: Colors.white),
                              ),
                            ),
                          ),
                        ),
                        10.sizeBoxW,
                      ],
                      Expanded(
                        child: InkWell(
                            onTap: () {
                              Get.back(result: true);
                            },
                            child: Container(
                              alignment: Alignment.center,
                              child: Text(
                                "确定",
                                style: TextStyle(fontSize: 16, color: AppColors.primaryHighColor),
                              ),
                            )),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    ),
  );

  return res ?? false;
}

//背景bottomsheet弹窗包裹
Widget CommonSheetBgWidget(Widget child, {EdgeInsetsGeometry? padding}) {
  return Material(
    color: Colors.transparent,
    child: GestureDetector(
      onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
      child: Container(
        decoration: const BoxDecoration(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(18),
            topRight: Radius.circular(18),
          ),
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              Color(0xff141414),
              Colors.black,
            ],
          ),
        ),
        padding: padding,
        margin: EdgeInsets.zero,
        child: child,
      ),
    ),
  );
}

//背景dialog弹窗包裹
Widget CommonDiglogWidget(Widget child) {
  return GestureDetector(
    onTap: () => Get.back(),
    child: Material(
      color: Colors.transparent,
      child: GestureDetector(
        onTap: () => null,
        child: Center(
          child: child,
        ),
      ),
    ),
  );
}
